package com.gitee.zw.irmp.report.dao;

import com.gitee.zw.irmp.report.entity.ReportDef;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ReportDefRepository extends JpaRepository<ReportDef, Long> {
    @Query(value = "select t.id, t.parentId, t.reportCode, t.reportName, t.seq, f.userName " +
            "from ReportDef t left outer join ReportUserFavorite f on t.reportCode = f.reportCode and f.userName = ?1 " +
            "where t.category = ?2 and t.status = 'T'  order by t.parentId asc, t.seq asc", nativeQuery = true)
    List<Object[]> findByReportCatAndFavor(String userName, String cat);

    @Query("select ru.reportCode from ReportUserFavorite ru where ru.userName = ?1")
    List<String> getFavorReports(String userName);
}
